package friot.service.user.controller;

import friot.utils.tools.JwtUtil;
import friot.utils.tools.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author He Kuntao
 * @desc Token Controller
 * @date 2024/3/15 23:12
 */
@RestController
@RequestMapping("/api/token")
public class TokenController {

    @GetMapping("/gen")
    public Result genToken(HttpServletRequest request) {
        int userId = JwtUtil.parseTokenToUserId(request);
        String jwt = JwtUtil.generateToken("GenToken", String.valueOf(userId));
        return Result.success(jwt);
    }
}
